import { ref } from "vue";
import { defineStore } from "pinia";
import request from "@/lib/request.js";
import { handleRes } from "@/lib/common.js";
import useAppStore from "./app.js";
const appStore = useAppStore();
const useAuthStore = defineStore("auth", () => {
  // 定义 uid
  const uid = ref(null);
  // 定义令牌
  const token = ref(null);
  // 是否已登录
  const isLogin = ref(false);
  
  const userId = ref(null);

  // 定义获取函数
  function doLogin() {
    return new Promise(function (resolve, reject) {
      appStore.uniAuth().then((code) => {
        request({
          url: "/pms/wx/qlogin?code="+code,
          method: "POST",
          data: {
            code,
          },
        }).then((res) => {
			console.log(res)
          resolve(res.data);
        });
      });
    });
  }

  return {
    uid,
	userId,
	isLogin,
    token,
    doLogin,
  };
});
export default useAuthStore;
